package com.ruijie.autotest.log.common.sql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;

public class ResultSetIteratorAdapter implements Iterator<String> {
	private final ResultSet allValuesResultSet;

	private final SqlType type;

	public ResultSetIteratorAdapter(ResultSet allValuesResultSet, SqlType type) {
		this.allValuesResultSet = allValuesResultSet;
		this.type = type;
	}

	@Override
	public boolean hasNext() {
		try {
			return allValuesResultSet.next();
		} catch (SQLException e) {
			return false;
		}
	}

	@Override
	public String next() {
		try {
			return type.valueFrom(allValuesResultSet);
		} catch (SQLException e) {
			throw new RuntimeException("unexpected sql exception.", e);
		}
	}
}
